/*
 * Course:    CS 590 Web Services
 * Semseter:  Spring 2009
 * Professor: Sedlemeyer
 * Project:   CHEAT (Code Help Educational Assignment Tool)
 * Due Date:  May 1, 2009
 * Team:      Sarcasm
 *            (Baker, Jason; Mitchell, Robin; Shie, Keith)
 */

package cheat.entities;

import java.io.Serializable;
import java.util.Collection;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;


/**
 * Define the type of archives know within the system.
 *
 * @author Keith Shie
 */
@Entity
@Table( name = "archv_type" )
@NamedQueries( { @NamedQuery( name = "ArchiveType.findAll", query = "SELECT a FROM ArchiveType a" ),
                 @NamedQuery( name = "ArchiveType.findByName",
                              query = "SELECT a FROM ArchiveType a WHERE a.name = :name" ),
                 @NamedQuery( name = "ArchiveType.findByDescription",
                              query = "SELECT a FROM ArchiveType a WHERE a.description = :description" ) } )
public class ArchiveType implements Serializable {
  private static final long serialVersionUID = 1L;
  @Id
  @Basic( optional = false )
  @Column( name = "archv_typ", nullable = false, length = 8 )
  private String name;
  @Basic( optional = false )
  @Column( name = "descr", nullable = false, length = 30 )
  private String description;
  @OneToMany( cascade = CascadeType.ALL, mappedBy = "archiveType" )
  private Collection<AssignmentArchive> assignmentArchiveCollection;

  /**
   * String representing a Zip archive type
   */
  public static final String ZIP_ARCHIVE_TYPE = "zip";


  public ArchiveType() {
  }


  public ArchiveType( String name ) {
    this.name = name;
  }


  public ArchiveType( String name, String descr ) {
    this.name = name;
    this.description = descr;
  }


  public String getName() {
    return name;
  }


  public void setName( String name ) {
    this.name = name;
  }


  public String getDescription() {
    return description;
  }


  public void setDescription( String descr ) {
    this.description = descr;
  }


  public Collection<AssignmentArchive> getAssignmentArchiveCollection() {
    return assignmentArchiveCollection;
  }


  public void setAssignmentArchiveCollection( Collection<AssignmentArchive> assignmentArchiveCollection ) {
    this.assignmentArchiveCollection = assignmentArchiveCollection;
  }


  @Override
  public int hashCode() {
    int hash = 0;
    hash += ( name != null ? name.hashCode() : 0 );
    return hash;
  }


  @Override
  public boolean equals( Object object ) {
    // TODO: Warning - this method won't work in the case the id fields are not set
    if ( !( object instanceof ArchiveType ) ) {
      return false;
    }
    ArchiveType other = (ArchiveType) object;
    if ( ( this.name == null && other.name != null ) || ( this.name != null && !this.name.equals( other.name ) ) ) {
      return false;
    }
    return true;
  }


  @Override
  public String toString() {
    return "cheat.entities.ArchiveType[name=" + name + "]";
  }

}
